class DevicePixelRatio {
	constructor() {}
	//获取系统类型
	_getSystem() {
		const agent = navigator.userAgent.toLowerCase()
		if (agent.indexOf('windows') >= 0) {
			return true
		}
	}
	//获取页面缩放比例
	_addHandler(element, type, handler) {
		if (element.addEventListener) {
			element.addEventListener(type, handler, false)
		} else if (element.attachEvent) {
			element.attachEvent('on' + type, handler)
		} else {
			element['on' + type] = handler
		}
	}
	//校正浏览器缩放比例
	_correct() {
		let domEl: any = document.getElementsByTagName('body')[0].style
		const zoom = 1 / window.devicePixelRatio
		domEl.zoom = zoom<0.6?0.6:zoom
		// domEl.zoom = zoom <1 ? 0.9 : zoom
	}
	_watch() {
		let t = this
		t._addHandler(window, 'resize', () => {
			t._correct()
		})
	}
	//初始化页面比例
	init() {
		let t = this
		if (t._getSystem()) {
			t._correct()
			t._watch()
		}
	}
}
export default DevicePixelRatio
